From version 2.0 we hava our clenaed data with no rows and columns with total values we have pure data assoctated wth each crime bow lets sepearte all crimes individually

Note file name:

>>crimescleaned.csv

In [1]:
#Include libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

In [22]:
crimes = pd.read_csv('crimescleaned.csv', index_col=0)
crimes.head() #seems and unwanted column is added


Out[22]:
STATE/UT CRIME HEAD 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012
0 ANDHRA PRADESH RAPE 871 1002 946 1016 935 1049 1070 1257 1188 1362 1442 1341
1 ARUNACHAL PRADESH RAPE 33 38 31 42 35 37 48 42 59 47 42 46
2 ASSAM RAPE 817 970 1095 1171 1238 1244 1437 1438 1631 1721 1700 1716
3 BIHAR RAPE 888 1040 985 1390 1147 1232 1555 1302 929 795 934 927
4 CHHATTISGARH RAPE 959 992 898 969 990 995 982 978 976 1012 1053 1034

In [31]:
pd.unique(crimes['CRIME HEAD'])


Out[31]:
array(['RAPE', 'KIDNAPPING and ABDUCTION', 'DOWRY DEATHS',
       'ASSAULT ON WOMEN WITH INTENT TO OUTRAGE HER MODESTY',
       'INSULT TO THE MODESTY OF WOMEN',
       'CRUELTY BY HUSBAND OR HIS RELATIVES (IPC SECTION 498A)',
       'IMPORTATION OF GIRLS FROM FOREIGN COUNTRY',
       'IMMORAL TRAFFIC (P) ACT', 'DOWRY PROHIBITION ACT',
       'INDECENT REPRESENTATION OF WOMEN (P) ACT',
       'COMMISSION OF SATI PREVENTION ACT'], dtype=object)

Now lets seprate each crime from the data and make sperate datframe and then csv files


In [43]:
crimelist = pd.unique(crimes['CRIME HEAD'])
crimelist


Out[43]:
array(['RAPE', 'KIDNAPPING and ABDUCTION', 'DOWRY DEATHS',
       'ASSAULT ON WOMEN WITH INTENT TO OUTRAGE HER MODESTY',
       'INSULT TO THE MODESTY OF WOMEN',
       'CRUELTY BY HUSBAND OR HIS RELATIVES (IPC SECTION 498A)',
       'IMPORTATION OF GIRLS FROM FOREIGN COUNTRY',
       'IMMORAL TRAFFIC (P) ACT', 'DOWRY PROHIBITION ACT',
       'INDECENT REPRESENTATION OF WOMEN (P) ACT',
       'COMMISSION OF SATI PREVENTION ACT'], dtype=object)

In [61]:
#rape,kidnapping  = crimes[crimes['CRIME HEAD']=='RAPE'], crimes[crimes['CRIME HEAD']=='KIDNAPPING and ABDUCTION']
for crime in crimelist:
    print crime


RAPE
KIDNAPPING and ABDUCTION
DOWRY DEATHS
ASSAULT ON WOMEN WITH INTENT TO OUTRAGE HER MODESTY
INSULT TO THE MODESTY OF WOMEN
CRUELTY BY HUSBAND OR HIS RELATIVES (IPC SECTION 498A)
IMPORTATION OF GIRLS FROM FOREIGN COUNTRY
IMMORAL TRAFFIC (P) ACT
DOWRY PROHIBITION ACT
INDECENT REPRESENTATION OF WOMEN (P) ACT
COMMISSION OF SATI PREVENTION ACT

In [65]:
for crime in crimelist:
    df = crimes[crimes['CRIME HEAD']== crime]
    df.to_csv(crime+'.csv')

Now we have a seperate csv files with different crimes which we can load sperately whenever we want


In [74]:
import os
DIR_PATH = os.getcwd() + '//crimes'

In [75]:
DIR_PATH


Out[75]:
'F:\\Educational Stuff\\Hebi\\Machine Learning and Data Science\\Data Science\\My_Work\\crime_against_women//crimes'

In [86]:
for filenames in (os.walk(DIR_PATH)):
    for filename in filenames:
        print filename


F:\Educational Stuff\Hebi\Machine Learning and Data Science\Data Science\My_Work\crime_against_women//crimes
[]
['ASSAULT ON WOMEN WITH INTENT TO OUTRAGE HER MODESTY.csv', 'COMMISSION OF SATI PREVENTION ACT.csv', 'CRUELTY BY HUSBAND OR HIS RELATIVES (IPC SECTION 498A).csv', 'DOWRY DEATHS.csv', 'DOWRY PROHIBITION ACT.csv', 'IMMORAL TRAFFIC (P) ACT.csv', 'IMPORTATION OF GIRLS FROM FOREIGN COUNTRY.csv', 'INDECENT REPRESENTATION OF WOMEN (P) ACT.csv', 'INSULT TO THE MODESTY OF WOMEN.csv', 'KIDNAPPING and ABDUCTION.csv', 'RAPE.csv']

In [88]:
#This sounds Cool
for filename in os.listdir(DIR_PATH):
    print  filename


ASSAULT ON WOMEN WITH INTENT TO OUTRAGE HER MODESTY.csv
COMMISSION OF SATI PREVENTION ACT.csv
CRUELTY BY HUSBAND OR HIS RELATIVES (IPC SECTION 498A).csv
DOWRY DEATHS.csv
DOWRY PROHIBITION ACT.csv
IMMORAL TRAFFIC (P) ACT.csv
IMPORTATION OF GIRLS FROM FOREIGN COUNTRY.csv
INDECENT REPRESENTATION OF WOMEN (P) ACT.csv
INSULT TO THE MODESTY OF WOMEN.csv
KIDNAPPING and ABDUCTION.csv
RAPE.csv

In [ ]: